<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="common.jsp" %>
<%            // Main Application Logic Comes Here
            ArrayList<Project> projects = ProjectDAO.retrieveAllBidableProjects();
            ArrayList<Bid> bids_of_this_player = BidDAO.retrieveAllBidsOfPlayer(ManagePlayer.getThisPlayer(request).getPlayer_id());

%>

<HTML>
    <c:set var="title" value="MIC Tycoon ~ Project Page"/>
    <%@ include file="htmlheader.jsp" %>

    <body>
        <div id="resolution">

            <%@ include file="header.jsp" %>

            <div id="content">

                <!-- show announcements -->
                <c:if test="${announcement!=null}">
                    <div id="announcement">
                        <p><c:out value="${announcement}"/></p>
                    </div>
                </c:if>

                ${error_message}
                ${success_message}

                <% if (projects.size() > 0 || true) {%>
                <form method="post" action="/wargaming/bid/bidProject.do">
                    <table border="1">
                        <tr align="center">
                            <td rowspan="2">Project ID</td>
                            <td rowspan="2">Project Offered By</td>
                            <td colspan="8">Man Hours Required</td>
                            <td rowspan="2">Max Bid</td>
                            <td rowspan="2">Turn Due</td>
                            <td rowspan="2">Bidding Price</td>
                            <td rowspan="2">Bid</td>
                        </tr>
                        <tr>
                            <td>.Net</td>
                            <td>C#</td>
                            <td>JSP</td>
                            <td>PHP</td>
                            <td>Ruby</td>
                            <td>MySQL</td>
                            <td>MsSQL</td>
                            <td>Oracle</td>
                        </tr>
                        <% for (int i = 0; i < projects.size(); i++) {%>
                        <% Project p = projects.get(i);%>
                        <tr>
                            <td><%=p.getProject_id()%></td>
                            <td><%=p.getOffered_by()%></td>
                            <td><%=p.getMan_hours_dot_net()%></td>
                            <td><%=p.getMan_hours_c_sharp()%></td>
                            <td><%=p.getMan_hours_jsp()%></td>
                            <td><%=p.getMan_hours_php()%></td>
                            <td><%=p.getMan_hours_ruby()%></td>
                            <td><%=p.getMan_hours_mysql()%></td>
                            <td><%=p.getMan_hours_mssql()%></td>
                            <td><%=p.getMan_hours_oracle()%></td>
                            <td><%=formatCurrency(p.getMax_bid())%></td>
                            <td><%=p.getDue_turn()%></td>
                            <%

                                 int amount_placed = 0; // 0 means bid not placed
                                 for (int j = 0; j < bids_of_this_player.size(); j++) {

                                     if (bids_of_this_player.get(j).getProject_id() == p.getProject_id()) {

                                         amount_placed = bids_of_this_player.get(j).getAmount();

                                     }
                                 }
                            %>
                            <% if (amount_placed == 0) {%>
                            <td>$<input type="text" name="bid_amount_project_id_<%=p.getProject_id()%>"></td>
                            <td><input type="checkbox" name="bid_project_id[]" value="<%=p.getProject_id()%>"></td>
                                <% } else {%>
                            <td><%= formatCurrency(amount_placed)%></td>
                            <td colspan="2">Bid Placed</td>
                            <% }%>
                        </tr>
                        <% }%>
                        <tr>
                            <td colspan="14" align="right"><input type="submit" value="Bid"></td>
                        </tr>
                    </table>


                </form>
                <% }%>
            </div>
        </div>
    </BODY>
</HTML>
